<!-- image -->
<template>
  <div class="ai-image">
    <div class="left">
      <div class="segmented">
        <el-segmented v-model="selectFuncType" :options="funcTypeOptions" />
      </div>
      <div class="modal-switch-container">
        <ImageToVideo
          v-if="selectFuncType === AiCreateVideoEnum.IMAGE_VIDEO"
          ref="imageToVideo"
          @on-create-start="handleCreateStart"
          @on-create-complete="handleCreateComplete"
        />
      </div>
    </div>
    <div class="main">
      <VideoList ref="videoListRef"
                  @on-regeneration="handleRegeneration"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import VideoList from './components/VideoList.vue'
import {AiCreateVideoEnum} from '@/views/ai/utils/constants'
import ImageToVideo from './components/runway/index.vue'
import {VideoVO} from "@/api/ai/video";
// const message = useMessage()

const videoListRef = ref<any>() // video 列表 ref
const imageToVideo = ref<any>() // imageToVideo(meshy.ai) ref

// 定义属性
const selectFuncType = ref(AiCreateVideoEnum.IMAGE_VIDEO)
const funcTypeOptions = [
  {
    label: '图生视频',
    value: AiCreateVideoEnum.IMAGE_VIDEO
  },
]

/** 模型 start  */
const handleCreateStart = async () => {

}

/** 模型 complete */
const handleCreateComplete = async () => {
  await videoListRef.value.getVideoList()
}

/**  重新生成：将模型详情填充到对应平台  */
const handleRegeneration = async (video:VideoVO) => {
  // 根据不同平台填充 video
  selectFuncType.value = video.funcType;
  await nextTick()
  if (video.funcType === AiCreateVideoEnum.IMAGE_VIDEO) {
    imageToVideo.value.settingValues(video)
  }
}

</script>

<style scoped lang="scss">
.ai-image {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;

  display: flex;
  flex-direction: row;
  height: 100%;
  width: 100%;

  .left {
    display: flex;
    flex-direction: column;
    padding: 20px;
    width: 350px;

    .segmented {
      position: absolute;left: 0px; top: 10px;
    }

    .segmented .el-segmented {
      --el-border-radius-base: 16px;
      --el-segmented-item-selected-color: #fff;
      background-color: #ececec;
      width: 350px;
    }

    .modal-switch-container {
      height: 100%;
      overflow-y: auto;
      margin-top: 30px;
    }
  }

  .main {
    flex: 1;
    background-color: #fff;
  }

  .right {
    width: 350px;
    background-color: #f7f8fa;
  }
}
</style>
